<template>
  <a-drawer
    title="编辑随访计划"
    :width="600"
    :visible.sync="visible"
    :body-style="{'padding-top': '0px', paddingBottom: '80px' }"
    @close="close"
  >
    <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 17 }" layout="horizontal">
      <a-form-item label="随访详情">
        <a-textarea
          v-decorator="['info', { rules: [{ required: true, message: '随访详情不能为空!' }] }]"
          placeholder="请输入随访详情"
          :auto-size="{ minRows: 3, maxRows: 5 }"
        />
      </a-form-item>
    </a-form>

    <div
      class="absolute right-0 bottom-0 w-full border-t border-[#e9e9e9] px-4 py-[10px] bg-white text-left z-1 flex justify-center"
    >
      <a-button :style="{ marginRight: '20px' }" class="w-[200px]" @click="close">取消</a-button>
      <a-button
        :loading="loading"
        class="w-[200px]"
        type="primary"
        @click.native.prevent="submit()"
      >
        <span v-if="!loading">提交计划</span>
        <span v-else>提交中...</span>
      </a-button>
    </div>
  </a-drawer>
</template>

<script>
import { editFollowupDetail } from '@/api/index'
import moment from 'moment'
export default {
  data() {
    return {
      form: this.$form.createForm(this),

      docterList: [],
      visible: false,
      loading: false,
      listLoading: false,
      id: 0,
    }
  },
  mounted() {},
  methods: {
    /**
     *
     * @param {*} data 数据
     */
    async open(data = {}) {
      this.visible = true
      this.id = data.Id
      try {
        await this.$nextTick()
        this.form.setFieldsValue({
          info: data.DpfuInfo,
        })
      } catch (error) {
        this.$message.error(error)
      }
    },
    submit() {
      const {
        form: { validateFields },
      } = this
      const id = this.id
      this.loading = true
      validateFields(['info'], { force: true }, async (err, values) => {
        if (!err) {
          try {
            await editFollowupDetail({ ...values, id })
            this.$emit('succeed')
            this.$message.success('操作成功！')
            this.close()
          } catch (error) {
            this.$message.error(error)
          } finally {
            this.loading = false
          }
        } else {
          setTimeout(() => {
            this.loading = false
          }, 600)
        }
      })
    },
    close() {
      this.visible = false
      this.form.resetFields()
    },
  },
}
</script>
<style lang="less" scoped>
.shadow {
  box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.2);
}
</style>